package com.example.database_manage.admin;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.database_manage.R;
import com.example.database_manage.database.CommonDatabase;


/***
 * 管理员用于增加学生信息
 */
public class add extends AppCompatActivity implements View.OnClickListener {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        //实现add_activity中的按钮绑定
        Button button_add_add = findViewById(R.id.button_add_add);

        Button button_finish_add = findViewById(R.id.button_finish_add);

        //为这两个按钮实现Click监听器
        button_finish_add.setOnClickListener(this);

        button_add_add.setOnClickListener(this);

    }
    @Override
    public void onClick(View v) {
        CommonDatabase commonDatabase = new CommonDatabase();
        SQLiteDatabase db =commonDatabase.getSqliteObject(add.this,"test_db");

        //获取用户输入的学号
        EditText edit_student_id = findViewById(R.id.edit_student_id);

        String id = edit_student_id.getText().toString();
        //获取用户输入的姓名
        EditText edit_student_name = findViewById(R.id.edit_student_name);

        String name = edit_student_name.getText().toString();

        //获取用户输入的性别
        EditText edit_student_sex = findViewById(R.id.edit_student_sex);

        String sex = edit_student_sex.getText().toString();

        //获取用户输入的年龄
        EditText edit_student_age = findViewById(R.id.edit_student_age);

        String age = edit_student_age.getText().toString();

        //获取用户输入的班级
        EditText edit_student_class = findViewById(R.id.edit_student_class);

        String classroom = edit_student_class.getText().toString();

        //获取用户输入的生日
        EditText edit_student_birth = findViewById(R.id.edit_student_birth);

        String birth = edit_student_birth.getText().toString();

        //输入用户输入的社团
        EditText edit_student_clubInfo = findViewById(R.id.edit_student_clubInfo);

        String clubInfo = edit_student_clubInfo.getText().toString();

        //输入用户输入的获奖
        EditText edit_student_awards = findViewById(R.id.edit_student_awards);

        String awards = edit_student_awards.getText().toString();

        //输入用户输入的毕业
        EditText edit_student_work = findViewById(R.id.edit_student_work);

        String work = edit_student_work.getText().toString();



        {

            switch (v.getId())
            {
                case R.id.button_add_add:
                    ContentValues values = new ContentValues();
                    values.put("id",id);
                    values.put("sname",name);
                    values.put("classroom",classroom);
                    values.put("sex",sex);
                    values.put("age",age);
                    values.put("birth",birth);
                    values.put("clubInfo",clubInfo);
                    values.put("awards",awards);
                    values.put("graduationWork",work);
                    db.insert("student", null, values);

                    finish();
                    break;
                case R.id.button_finish_add:
                    finish();
                    break;
                default:
                    break;
            }
        }



    }
}
